package modelLayer;

import java.util.ArrayList;
/**
 * Write a description of class DVDContainer here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class DVDContainer
{
    // instance variables - replace the example below with your own
    private ArrayList<DVD> dvdList;
    private static DVDContainer instance;
    

    /**
     * Constructor for objects of class DVDContainer
     */
    // Singleton => private constructor
    private DVDContainer()
    {
        dvdList = new ArrayList<DVD>();
    }

    //Singleton getInstance() method
    public static DVDContainer getInstance() 
    {
        if(instance == null) 
        {
            instance = new DVDContainer();
        }
        return instance;
    }
    
    
    public void addDVD(DVD dvd)
    {
        if(!dvdList.contains(dvd))
        {
            dvdList.add(dvd);
        }
    }
    
    public DVD getDVD(String barcode)
    {
        DVD returnDVD = null;
        for(DVD dvd: dvdList)
        {
            if(dvd.getBarcode().equals(barcode))
            {
                returnDVD = dvd;
            }
        }
        return returnDVD;
    }    
    
    public void deleteDVD(DVD dvd)
    {
        dvdList.remove(dvd);
    }
}
